package com.bxl.chooser.client;


import com.bxl.netty.rpc.common.context.Context;
import com.bxl.netty.rpc.common.serialize.KryoSerialize;
import com.bxl.netty.rpc.common.serialize.Serialize;
import com.bxl.netty.rpc.common.util.HandlerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * <>
 *
 * @author baixl
 * @date 2021/3/5
 */
public class ChooseClientContextImpl implements ChooseClientContext {
    private List<HandlerFactory> handler;
    private Serialize serialize;
    private List<HandlerFactory> decoder;
    private List<HandlerFactory> encoder;

    public Context init() {
        configSerialize();
        configHandler();
        configDecoder();
        configEncoder();
        return this;
    }

    protected void configDecoder() {
        decoder = new ArrayList<HandlerFactory>();
        decoder.add(new HandlerFactory<Context>(ChooseClientMsgDecoder.class));
    }

    protected void configEncoder() {
        encoder = new ArrayList<HandlerFactory>();
        encoder.add(new HandlerFactory<Context>(ChooseClientMsgEncoder.class));
    }

    protected void configHandler() {
        handler = new ArrayList<HandlerFactory>();
        handler.add(new HandlerFactory<Context>(ChooseClientHandler.class));
    }

    /**
     * 可以修改为配置化
     */
    protected void configSerialize() {
        serialize = new KryoSerialize();
    }

    public List<HandlerFactory> getHandler() {
        return handler;
    }

    public void setHandler(List<HandlerFactory> handler) {
        this.handler = handler;
    }

    public Serialize getSerialize() {
        return serialize;
    }

    public void setSerialize(Serialize serialize) {
        this.serialize = serialize;
    }

    public List<HandlerFactory> getDecoder() {
        return decoder;
    }

    public void setDecoder(List<HandlerFactory> decoder) {
        this.decoder = decoder;
    }

    public List<HandlerFactory> getEncoder() {
        return encoder;
    }

    public void setEncoder(List<HandlerFactory> encoder) {
        this.encoder = encoder;
    }
}
